package com.liuzhen.servlet;

import jakarta.servlet.*;

import java.io.IOException;
import java.util.Enumeration;

public class Servlet7 implements Servlet {
    @Override
    public void init(ServletConfig servletConfig) throws ServletException {
        //getServletContext() 获取ServletContext对象->代表的是整个web应用程序的对象
        ServletContext servletContext = servletConfig.getServletContext();
        System.out.println("servletContext = " + servletContext);
        //getServletName() -> 获取web.xml中servlet-name参数的
        String servletName = servletConfig.getServletName();
        System.out.println("servletName = " + servletName);

        //getInitParameter(String key)-> 获取在web.xml中给servlet初始化值的方法
        String value1 = servletConfig.getInitParameter("key1");
        System.out.println("value1 = " + value1);

        //getInitParameterNames() -> 获取所有的初始化参数的
        Enumeration<String> enumeration = servletConfig.getInitParameterNames();
        while (enumeration.hasMoreElements()) {
            String key = enumeration.nextElement();
            System.out.println(key + " = " + servletConfig.getInitParameter(key));
        }
    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        System.out.println("I am Servlet7");
    }

    @Override
    public String getServletInfo() {
        return "";
    }

    @Override
    public void destroy() {

    }
}